package com.ljb.android.comm.adapter.ktx

import androidx.annotation.NonNull
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * 加载更多数据，
 * 并多刷新上页的最后一个Item
 * */
fun <T> BaseQuickAdapter<T, *>.addDataAndLast(@NonNull newData: Collection<T>) {
    this.data.addAll(newData)
    // 多刷新上一页的最后一个
    val startPos = this.data.size - newData.size + headerLayoutCount
    val preLastPos = startPos - 1
    if (preLastPos > 0) {
        notifyItemChanged(preLastPos)
    }
    notifyItemRangeInserted(startPos, newData.size)
    if (this.data.size == newData.size) {
        notifyDataSetChanged()
    }
}